package com.cat.enumerate;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/powerful-integers/?envType=problem-list-v2&envId=enumeration
 * @create 2025/9/20 20:48
 * @since JDK17
 */

public class Solution06 {
    public List<Integer> powerfulIntegers(int x, int y, int bound) {
        Set<Integer> ans = new HashSet<>();
        int val1 = 1, val2 = 1;
        for (int i = 0; i < 21; i++) {
            int val = val1 + val2;
            for (int j = 0; j < 21; j++) {
                if (val <= bound) {
                    ans.add(val);
                } else {
                    break;
                }
                val2 *= y;
            }
            val1 *= x;
        }

        return ans.stream().toList();
    }
}
